package net.ithe.controller;

import lombok.extern.slf4j.Slf4j;
import net.ithe.pojo.Clazz;
import net.ithe.pojo.ClazzQueryParam;
import net.ithe.pojo.PageResult;
import net.ithe.pojo.Result;
import net.ithe.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/clazzs")
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    @GetMapping
    public Result  page(ClazzQueryParam clazzQueryParam) {
        log.info("分页查询班级数据,参数:{}",clazzQueryParam);
        PageResult<Clazz> pageResult=clazzService.page(clazzQueryParam);
        return Result.success(pageResult);
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("批量删除班级数据,参数:{}",id);
        clazzService.delete(id);
        return Result.success();
    }
    /**
     * 保存班级数据
     * @param clazz
     * @return
     */
    @PostMapping
    public Result save(@RequestBody Clazz clazz) {
        log.info("保存班级数据,参数:{}",clazz);
        clazzService.save(clazz);
        return Result.success();
    }
    /**
     * 根据id查询班级数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id) {
        log.info("根据id查询班级数据,参数:{}",id);
        Clazz clazz=clazzService.getById(id);
        return Result.success(clazz);
    }
    @PutMapping
    public Result update(@RequestBody Clazz clazz) {
        clazzService.update(clazz);
        return Result.success();
    }
    @GetMapping("/list")
    public Result list() {
        List<Clazz> clazzList=clazzService.listAll();
        return Result.success(clazzList);
    }
}
